package cn.wolfcode.luowowo.mgrsite.controller;

import cn.wolfcode.luowowo.article.domain.Destination;
import cn.wolfcode.luowowo.article.domain.Region;
import cn.wolfcode.luowowo.article.query.RegionQuery;
import cn.wolfcode.luowowo.article.service.IDestinationService;
import cn.wolfcode.luowowo.article.service.IRegionService;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/region")
public class RegionController {

    @Reference
    private IRegionService regionService;
     @Reference
     private IDestinationService destinationService;
    /**
     * 页面list数据
     * @param qo
     * @param model
     * @return
     */
    @RequestMapping("/list")
    public String list(@ModelAttribute("qo")RegionQuery qo, Model model){

        model.addAttribute("pageInfo",regionService.query(qo));
        return "/region/list";
    }

    /**
     * 根据deep查询相关目的地:要求deep<=3
     * @param
     * @return
     */
    @RequestMapping("/getDestByDeep")
    @ResponseBody
    public List<Destination> getDestByDeep(int deep){
        List<Destination> destList = destinationService.getDestByDeep(deep);
        return destList;

    }

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Region region){

        regionService.saveOrUpdate(region);
        return new AjaxResult();
    }

    @RequestMapping("/changeHotValue")
    @ResponseBody
    public Object changeHotValue(Long id,Boolean hot){

        regionService.changeHotValue(id,hot);
        return new AjaxResult();
    }

    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(Long id){

        regionService.delete(id);
        return new AjaxResult();
    }

    @RequestMapping("/getDestByRegionId")
    @ResponseBody
    public List<Destination> getDestByRegionId(Long rid){

        return destinationService.getDestByRegionId(rid);
    }
}
